package com.stox.core.dao.mapper;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.stox.core.model.Sector;

public class SectorRowMapper implements RowMapper<Sector> {

	public static final String createScripMappingSql = "create table sector_scrip(" +
			"sectorcode varchar(50) not null," +
			"scripcode varchar(20) not null," +
			"primary key (sectorcode,scripcode))";
	public static final String createSql = "create table sector(" +
			"code varchar(50) not null primary key," +
			"name varchar(50) not null," +
			"exchangeCode varchar(50) not null)";
	public static final String createIndexSql = "create unique index index_sector on sector(code)";
	public static final String selectSql = "select s.code, s.name, s.exchangeCode from Sector s ";
	public static final String insertSql = "insert into sector(code, name, exchangeCode) values(?,?,?)";
	
	@Override
	public List<Sector> map(ResultSet rs) throws SQLException {
		List<Sector> sectors = new ArrayList<Sector>();
		while(rs.next()){
			Sector sector = new Sector();
			sectors.add(sector);
			sector.setCode(rs.getString("code"));
			sector.setName(rs.getString("name"));
			sector.setExchangeCode(rs.getString("exchangeCode"));
		}
		return sectors;
	}

	@Override
	public void map(PreparedStatement ps, Sector sector) throws SQLException {
		if(sector != null){
			ps.setString(1, sector.getCode());
			ps.setString(2, sector.getName());
			ps.setString(3, sector.getExchangeCode());
		}
	}
	
}
